package com.ltkj.baseplatform.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ltkj.baseplatform.domain.SerSuggestion;
import com.ltkj.baseplatform.domain.bo.SerSuggestionBo;
import com.ltkj.baseplatform.domain.vo.SerSuggestionVO;
import com.ltkj.baseplatform.service.ISerSuggestionService;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.common.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 投诉建议Controller
 * 
 * @author chenzeen
 * @date 2023-08-29
 */
@Api(tags = "投诉建议")
@RestController
@RequestMapping("/suggestion")
public class SerSuggestionController extends BaseController
{
    @Autowired
    private ISerSuggestionService serSuggestionService;

    /**
     * 查询投诉建议列表
     */
    @ApiOperation("查询投诉建议列表")
    @RequiresPermissions("baseplatform:suggestion:list")
    @GetMapping("/list")
    public TableDataInfo list(SerSuggestion serSuggestion)
    {
        startPage();
        List<SerSuggestionVO> list = serSuggestionService.selectSerSuggestionListVO(serSuggestion);
        return getDataTable(list);
    }

    @ApiOperation("查询本人投诉建议列表")
    @RequiresPermissions("baseplatform:suggestion:list")
    @GetMapping("/listForme")
    public TableDataInfo listForme(SerSuggestion serSuggestion)
    {
        startPage();
        serSuggestion.setUserId(""+SecurityUtils.getLoginUser().getUserid());
        List<SerSuggestionVO> list = serSuggestionService.selectSerSuggestionListVO(serSuggestion);
        return getDataTable(list);
    }

    /**
     * 导出投诉建议列表
     */
    @ApiOperation("导出投诉建议列表")
    @RequiresPermissions("baseplatform:suggestion:export")
    @Log(title = "投诉建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SerSuggestion serSuggestion)
    {
        List<SerSuggestion> list = serSuggestionService.selectSerSuggestionList(serSuggestion);
        ExcelUtil<SerSuggestion> util = new ExcelUtil<SerSuggestion>(SerSuggestion.class);
        util.exportExcel(response, list, "投诉建议数据");
    }

    /**
     * 获取投诉建议详细信息
     */
    @ApiOperation("获取投诉建议详细信息")
    @RequiresPermissions("baseplatform:suggestion:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serSuggestionService.selectSerSuggestionVOById(id));
    }

    /**
     * 新增投诉建议
     */
    @ApiOperation("新增投诉建议")
    @RequiresPermissions("baseplatform:suggestion:add")
    @Log(title = "投诉建议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SerSuggestionBo serSuggestionBo)
    {
        SerSuggestion ss = new SerSuggestion();
        ss = BeanUtil.copyProperties(serSuggestionBo, SerSuggestion.class);
        return toAjax(serSuggestionService.insertSerSuggestion(ss,serSuggestionBo.getAttaIds()));
    }

    /**
     * 修改投诉建议
     */
    @ApiOperation("修改投诉建议")
    @RequiresPermissions("baseplatform:suggestion:edit")
    @Log(title = "投诉建议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SerSuggestion serSuggestion)
    {
        return toAjax(serSuggestionService.updateSerSuggestion(serSuggestion));
    }

    /**
     * 删除投诉建议
     */
    @ApiOperation("删除投诉建议")
    @RequiresPermissions("baseplatform:suggestion:remove")
    @Log(title = "投诉建议", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serSuggestionService.deleteSerSuggestionByIds(ids));
    }
}
